package com.example.administrator.daggerdemo.module;

import com.example.administrator.daggerdemo.MyApplication;
import com.example.administrator.daggerdemo.model.network.response.GetSMSCodeResponseInfo;
import com.example.administrator.daggerdemo.model.network.response.GetgrowResponseInfo;
import com.example.administrator.daggerdemo.model.network.response.LoginResponseInfo;
import com.example.administrator.daggerdemo.model.network.response.RegisterResponseInfo;
import com.example.administrator.daggerdemo.module.api.TestApi;
import com.example.administrator.daggerdemo.utils.GsonUtils;
import com.google.gson.Gson;

import org.json.JSONException;


import rx.Observable;

/**
 * 网络管理调用类
 * Created by zhengjian on 2016/12/9.
 */
public class NetWorkManager {
    private static NetWorkManager ourInstance = new NetWorkManager();

      static TestApi api;
    public static NetWorkManager getInstance() {
        api= NetWorkUtils.getXQXAPIservice();
        return ourInstance;
    }

    private NetWorkManager() {
    }


    /**
     * 登录
     * @param data
     * @return
     * @throws JSONException
     */
    public Observable<LoginResponseInfo> doLogin(Object data) throws JSONException
    {
       return api.login(GsonUtils.setCMD("10102"),GsonUtils.setData(data));
    }

    /**
     * 获取短信
     * @param data
     * @return
     * @throws JSONException
     */
    public Observable<GetSMSCodeResponseInfo> doGetSMS(Object data) throws JSONException
    {
        return api.getSMSCode(GsonUtils.setCMD("10100"), GsonUtils.setData(data));
    }

    /**
     * 注册
     * @param data
     * @return
     * @throws JSONException
     */
    public Observable<RegisterResponseInfo> doRegister(Object data) throws JSONException
    {
        return api.register(GsonUtils.setCMD("10101"), GsonUtils.setData(data));
    }

    /**
     * 获取成长记录
     * @param data
     * @return
     * @throws JSONException
     */
    public Observable<GetgrowResponseInfo> getGrowList(Object data) throws JSONException
    {
        return api.getGrowInfo(GsonUtils.setCMD("10109"), GsonUtils.setData(data), MyApplication.DOTOKEN);
    }
}
